<template>
  <div id="app">
    <h1>爸爸有存款：{{ money }}</h1>
    <button @click="jieqianxm(150)">找小明借了150</button>
    <button @click="jieqianxh(100)">找小红借了100</button>
    <button @click="all(200)">找所有孩子借钱200</button>
    <son ref="xm"></son>
    <gril ref="xh"></gril>
  </div>
</template>
<script>
import Son from "./components/Xm.vue";
import Gril from "./components/Xh.vue";
export default {
  components: {
    Son,
    Gril,
  },
  data() {
    return {
      money: 1000,
    };
  },
  methods: {
    jieqianxm(money) {
      this.money += money;
      console.log(this.$refs.xm.money); //获取到子组件的实列
      this.$refs.xm.money -= money;
    },
    jieqianxh(money) {
      this.money += money;
      this.$refs.xh.money -= money;
    },
    all(money) {
      this.money += 2 * money;
      // this.$children能获取所有的父组件
      console.log(this.$children);
      this.$children.forEach((item) => {
        item.money -= money;
      });
    },
  },
};
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
